[#ftl]
[#import "common/macrolibs.ftl" as lib]
[#assign mtmtable][@lib.mtmTableName  mtm=relation/][/#assign]
[#assign mtmalias]mtm${relation.id}[/#assign]
[#assign masterid]t${master.id}mid[/#assign]
[#assign  slaveid]t${slave.id}sid[/#assign]
[#assign masteralias]t${master.id}[/#assign]
[#assign slavealias]t${slave.id}[/#assign]
[#assign fkmaster]FK_${mtmalias}_${masterid}_${masteralias}[/#assign]
[#assign fkslave]FK_${mtmalias}_${slaveid}_${slavealias}[/#assign]
CREATE TABLE [${mtmtable}] (
  [${masterid}] bigint foreign key(${masterid}) references [@lib.fullTableName clazz=relation.master/](id),
  [${slaveid}] bigint foreign key(${slaveid}) references [@lib.fullTableName clazz=relation.slave/](id)
)
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'${fkmaster}' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'${mtmtable}', @level2type=N'COLUMN', @level2name=N'${masterid}'
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'${fkslave}' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'${mtmtable}', @level2type=N'COLUMN', @level2name=N'${slaveid}'
